import { expect } from 'chai';
import stripInlineStyle from '../src/stripInlineStyle.js';

describe('stripInlineStyle unit test', function () {
    it('处理空值', function () {
        expect(stripInlineStyle()).to.be.eql('');
    });

    it('返回原始数据', function () {
        expect(stripInlineStyle('a')).to.be.eql('a');
    });

    it('处理空值', function () {
        expect(stripInlineStyle('a', [])).to.be.eql('a');
    });

    it('删除标签的內联样式', function () {
        const input = '<a href="xxx" style="width:100px;">Link</a>';
        const want = '<a href="xxx">Link</a>';
        const got = stripInlineStyle(input);
        expect(got).to.be.eql(want);
    });

    it('删除所有标签的內联样式', function () {
        const input =
            '<a href="xxx" style="width:100px;">Link</a><p style="border: 1px solid red;">Hello</p>';
        const want = '<a href="xxx">Link</a><p>Hello</p>';
        const got = stripInlineStyle(input);
        expect(got).to.be.eql(want);
    });

    it('删除所有标签的內联样式', function () {
        const input =
            '<a href="xxx" style="width:100px;">Link</a><p style="border: 1px solid red;">Hello</p><img src="xxx" style="width:100px;" />';
        const want = '<a href="xxx">Link</a><p>Hello</p><img src="xxx" />';
        const got = stripInlineStyle(input);
        expect(got).to.be.eql(want);
    });

    it('删除指定标签的內联样式', function () {
        const input =
            '<a href="xxx" style="width:100px;">Link</a><p style="border: 1px solid red;">Hello</p><img src="xxx" style="width:100px;" />';
        const want =
            '<a href="xxx" style="width:100px;">Link</a><p style="border: 1px solid red;">Hello</p><img src="xxx" />';
        const got = stripInlineStyle(input, 'img');
        expect(got).to.be.eql(want);
    });

    it('删除指定标签的內联样式', function () {
        const input =
            '<a href="xxx" style="width:100px;">Link</a><p style="border: 1px solid red;">Hello</p><img src="xxx" style="width:100px;">';
        const want =
            '<a href="xxx" style="width:100px;">Link</a><p style="border: 1px solid red;">Hello</p><img src="xxx">';
        const got = stripInlineStyle(input, 'img');
        expect(got).to.be.eql(want);
    });

    it('删除指定标签的內联样式', function () {
        const input =
            '<a href="xxx" style="width:100px;">Link</a><p style="border: 1px solid red;">Hello</p><img src="xxx" style="width:100px;">';
        const want =
            '<a href="xxx">Link</a><p style="border: 1px solid red;">Hello</p><img src="xxx">';
        const got = stripInlineStyle(input, ['img', 'a']);
        expect(got).to.be.eql(want);
    });
});
